<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
         * {
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }
        .container{
            width: 600px;
            margin: 0 auto;
            padding: 20px 0;
        }
        .container-list {
            display: flex;
            justify-content: center;
            align-items: center;
            
        }
        .container-list  .row{
            width: 100%;
            height: 40px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 5px;
            background-color: rgba(0, 255, 255, 0.167);

        }
        .container-list h3{
            background-color: black;
            color: aliceblue;
            text-align: center;
            height: 40px;
            width: 300px;
        }
        .container-list> .todo, .done{
            width: 50%;
            height: 40px;
        }
        .container-input{
            margin-bottom: 10px;
        }
        .container-input .text{
            width: 490px;
            height: 40px;
        }
        .container-input #submit{
            width: 100px;
            height: 40px;
            background-color: rgb(235, 101, 29);
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="container-input">
            <input type="text" name="" id="task" class="text">
            <button id="submit">提交</button>
        </div>
        <div class="container-list">
            <div class="todo">
                <h3>未完成</h3>
            </div>
            <div class="done">
                <h3>已完成</h3>
            </div>
        </div>
       
    </div>
</body>
<script>
    // 1. 获取相关的标签
    let taskEl = document.querySelector('#task');
    let submitEl = document.querySelector('#submit');
    let todoEl = document.querySelector('.todo');
    let doneEl = document.querySelector('.done');
    //输入框的内容
    let text=document.querySelector("#task");
    //绑定事件
    submitEl.onclick=function(){
        //非空校验
        if(taskEl.value==''){
            alert("输入不能是空");
            return;
        }
        
    //创建div
    let divEl=document.createElement('div');
    divEl.className="row";
    //创建事件
    let checkboxEl = document.createElement('input');
        checkboxEl.type = 'checkbox';
    //创建输入
    let inputEl=document.createElement('span')
    inputEl.innerHTML=text.value;
    //创建span
    let del=document.createElement('button');
    del.innerHTML="删除";
    //绑定父事件
    divEl.appendChild(checkboxEl);
    divEl.appendChild(inputEl);
    divEl.appendChild(del);
     //加入任务列表
     todoEl.appendChild(divEl);
      //绑定事件
  checkboxEl.onclick=function(){
    if(checkboxEl.checked){
        doneEl.appendChild(divEl);
    }else{
        todoEl.appendChild(divEl);
    }
  }
  //删除结点
  del.onclick=function(){
    let parent=divEl.parentElement;
    parent.removeChild(divEl);
  }
  //将文本框置为空
  taskEl.value='';
    }
  
</script>
</html>